def combine_anagrams(words)
	words_sort_letters = words.collect { |word|
		word.downcase.split(//).sort.join
	}

	#create hash_map of indexes=>words
	#Hahs(words_sort_letters.each { |word|


	#take all unique strings(sorted letters)
	#for each such s string create a group: 
	#populate each group by taking all elements of word_sort_letters matching such string s
	
	temp_array = Array.new
	grouped_array = 
		words_sort_letters.uniq.collect { |group_id| 
			words_sort_letters.each { |word| 
				index_array = Array.new
				word == group_id ? index_array.push(words_sort_letters.index(word)) : ;
			}
		}
end
	input = 
	['cars', 'for', 'potatoes', 'racs', 'four','scar', 'creams', 'scream']
	 
	puts(combine_anagrams(input))

